#include "widget.h"
#include "ui_widget.h"
#include<QDebug>
#include<QRegExpValidator>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //设置按钮默认情况下是禁用的
    ui->pushButton->setEnabled(false);
    ui->lineEdit_phone->setValidator(new QRegExpValidator(QRegExp("^1\\d{10}$")));

    ui->lineEdit_name->setPlaceholderText("请输入姓名");
    ui->lineEdit_name->setClearButtonEnabled(true);

    ui->lineEdit_password->setPlaceholderText("请输入密码");
    ui->lineEdit_password->setClearButtonEnabled(true);
    ui->lineEdit_password->setEchoMode(QLineEdit::Password);

    ui->lineEdit_password_2->setPlaceholderText("重新确认密码");
    ui->lineEdit_password_2->setClearButtonEnabled(true);
    ui->lineEdit_password_2->setEchoMode(QLineEdit::Password);

    ui->lineEdit_phone->setPlaceholderText("请输入电话号码");
    ui->lineEdit_phone->setClearButtonEnabled(true);
//    ui->lineEdit_phone->setInputMask("000 0000 0000");
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    QString gender=ui->radioButton_male->isChecked()?"男":"女";
    qDebug()<<ui->lineEdit_name->text()<<"-"<<ui->lineEdit_password->text()<<"-"<<gender<<"-"<<ui->lineEdit_phone->text();
}

void Widget::on_lineEdit_phone_textEdited(const QString &arg1)
{
    qDebug()<<arg1;
    QString content=arg1;
    int pos=0;
    if(ui->lineEdit_phone->validator()->validate(content,pos)==QValidator::Acceptable)
    {
        ui->pushButton->setEnabled(true);
    }
    else
    {
        ui->pushButton->setEnabled(false);
    }

}

void Widget::on_lineEdit_password_2_textEdited(const QString &arg1)
{
    (void)arg1;
    const QString content1=ui->lineEdit_password->text();
    const QString content2=ui->lineEdit_password_2->text();
    if(content1.isEmpty()&&content2.isEmpty())
    {
        ui->label_info->setText("sorry,密码为空");
    }
    else if(content1==content2)
    {
        ui->label_info->setText("两次密码相同");
    }
    else
    {
        ui->label_info->setText("两次密码不相同");
    }
}

void Widget::on_lineEdit_password_textEdited(const QString &arg1)
{
    (void)arg1;
    const QString content1=ui->lineEdit_password->text();
    const QString content2=ui->lineEdit_password_2->text();
    if(content1.isEmpty()&&content2.isEmpty())
    {
        ui->label_info->setText("sorry,密码为空");
        ui->label_info->setStyleSheet("background-color:red");
    }
    else if(content1==content2)
    {
        ui->label_info->setText("两次密码相同");
        ui->label_info->setStyleSheet("background-color:blue");
    }
    else
    {
        ui->label_info->setText("两次密码不相同");
        ui->label_info->setStyleSheet("background-color:red");
    }
}


void Widget::on_checkBox_clicked(bool checked)
{
    if(checked)
    {
        ui->lineEdit_password->setEchoMode(QLineEdit::Normal);
    }
    else
    {
        ui->lineEdit_password->setEchoMode(QLineEdit::Password);
    }
}

void Widget::on_checkBox_2_clicked(bool checked)
{
    if(checked)
    {
        ui->lineEdit_password_2->setEchoMode(QLineEdit::Normal);
    }
    else
    {
        ui->lineEdit_password_2->setEchoMode(QLineEdit::Password);
    }
}
